// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class RESOURCES_CCM_I21 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 RGS",15)]
  	    [HL7Field(HL7Version.v27, 15, HL7Repeat.False, HL7Required.True,"RGS")]
	    public RGS RGS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("16 RESOURCE_DETAIL",16)]
  	    [HL7Field(HL7Version.v27, 16, HL7Repeat.True, HL7Required.False,"RESOURCE_DETAIL_CCM_I21")]
	    public RESOURCE_DETAIL_CCM_I21[] RESOURCE_DETAIL {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			RGS = PopSegmentParseAndCheckRequired<RGS>(availableData, options, "RGS");
			RESOURCE_DETAIL = ProcessGroupArray<RESOURCE_DETAIL_CCM_I21>(availableData, options, "RESOURCE_DETAIL");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isRGS = availableData.StartsWith("RGS", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RGS", options.Version) || isRGS) {
				return isRGS;
			}
			RESOURCE_DETAIL_CCM_I21 testRESOURCE_DETAIL_CCM_I21 = new RESOURCE_DETAIL_CCM_I21();
			bool grpCCRESOURCE_DETAIL_CCM_I21 = (testRESOURCE_DETAIL_CCM_I21.CanConsume(availableData, options));
			if (IsRequired("RESOURCE_DETAIL", options.Version) || grpCCRESOURCE_DETAIL_CCM_I21) {
				return grpCCRESOURCE_DETAIL_CCM_I21;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "RESOURCES";
			}
        }

        static RESOURCES_CCM_I21() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(RESOURCES_CCM_I21));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (RGS != null) {
			string segmentValue = RGS.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RESOURCE_DETAIL != null && RESOURCE_DETAIL.Length > 0) {
			for (int i = 0; i < RESOURCE_DETAIL.Length; i++) {
				string segmentValue = RESOURCE_DETAIL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

